package cn.wangzg.course0401;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.i(TAG, "onCreate: ");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, "onStart: ");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, "onResume: ");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG, "onPause: ");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i(TAG, "onStop: ");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy: ");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, "onRestart: ");
    }

    public void openSecond(View view) {
        startActivity(new Intent(this, SecondActivity.class));
    }

    public void openDialog(View view) {
        startActivity(new Intent(this,DialogActivity.class));
//        new AlertDialog.Builder(this)
//                .setTitle("提示")
//                .setMessage("测试！")
//                .setNegativeButton("取消",null)
//                .setPositiveButton("确定",null)
//                .show();
    }

    public void btnMode(View view){
        startActivity(new Intent(this, ActivityOne.class));
    }

    public void btnIntent(View view){
        Intent intent=new Intent("six");
        intent.addCategory("wang");
        intent.setDataAndType(Uri.parse("test://www.wang.cn:888/activity"),"aaa/bbb");
        //为了避免intent匹配不到Activity，直接去打开崩溃，
        // 打开之前先进行判断是否匹配到Activity
        if(intent.resolveActivity(getPackageManager())!=null) {
            startActivity(intent);
        }
    }
}
